<template>
  <template v-for="menu in userMenu">
    <!-- 先遍历父菜单 -->
    <el-sub-menu
      v-if="
        menu.children &&
        menu.children.length > 0 &&
        menu.children[0].menuType == 1
      "
      :key="menu._id"
      :index="menu.path"
    >
      <template #title>
        <el-icon>
          <component :is="menu.icon" />
        </el-icon>
        <span>{{ menu.menuName }}</span>
      </template>
      <!-- 父菜单有children再遍历子菜单  递归调用自己-->
      <tree-menu :userMenu="menu.children" />
    </el-sub-menu>

    <el-menu-item
      v-else-if="menu.menuType == 1"
      :index="menu.path"
      :key="menu._id + 1"
    >
      <el-icon>
        <component :is="menu.icon" />
      </el-icon>
      {{ menu.menuName }}
    </el-menu-item>
  </template>
</template>
<script>
export default {
  name: "TreeMenu",
  props: {
    userMenu: {
      type: Array,
      default() {
        return [];
      },
    },
  },
};
</script>